import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-03-22
 * Time: 22:43
 */
class Person implements Cloneable{
    @Override
    protected Object clone()
            throws CloneNotSupportedException {
        return super.clone();
    }
}
public class Test {
    public static int func3(){
        try(Scanner scanner = new Scanner(System.in)){
            int date = scanner.nextInt();
            return date;
        }catch (InputMismatchException e){
            e.printStackTrace();
        }finally {
            System.out.println("finally");
            return 0;
        }
    }
    public static int func2(){
        Scanner scanner = null;
        try{
            scanner = new Scanner(System.in);
            int date = scanner.nextInt();
            return date;
        }catch (InputMismatchException e){
            e.printStackTrace();
        }finally {
            System.out.println("finally");
            scanner.close();
        }
        System.out.println("666");
        return 0;
    }
    public static void main(String[] args) {
        //int ret = func2();
        int ret = func3();
    }
    public static void main8(String[] args) {
        int[] arr = {1, 2 ,3};
        try {
            System.out.println(arr[4]);
            arr = null;
            System.out.println(arr.length);
        }catch (NullPointerException e){
            System.out.println("捕获了NullPointerException异常");
            e.printStackTrace();
        }catch (Exception e){
            System.out.println("捕获了Exception异常");
            e.printStackTrace();
        }finally {
            System.out.println("finally执行了");//不论书否发生异常，finally都会被执行
        }
        System.out.println("66666666");
    }
    public static void main7(String[] args) {
        int[] arr = { 1, 2, 3};
        try{
            System.out.println(arr[4]);
            arr = null;
            System.out.println(arr.length);
        }catch (NullPointerException e){
            System.out.println("捕获了NullPointerException异常");
            e.printStackTrace();
        }catch (Exception e){
            System.out.println("捕获了Exception异常");
            e.printStackTrace();
        }
        System.out.println("666");
    }
    public static void main6(String[] args) {
        int[] arr = {1, 2, 3};
        try {
            System.out.println(arr[4]);
            arr = null;
            System.out.println(arr.length);
        } catch (ArrayIndexOutOfBoundsException | NullPointerException e) {
            System.out.println("捕获了ArrayIndexOutOfBoundsException | NullPointerException异常");
            e.printStackTrace();
        }
        System.out.println("666");
    }
    public static void main5(String[] args) {
        int[] arr = {1, 2, 3};
        try {
            System.out.println(arr[4]);
            arr = null;
            System.out.println(arr.length);
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("捕获了ArrayIndexOutOfBoundsException异常");
            e.printStackTrace();
        } catch (NullPointerException e) {
            System.out.println("捕获了NullPointerException异常");
            e.printStackTrace();
        }
        System.out.println("666");
    }
        public static void main4(String[] args) {
            int[] arr = {1 ,2 ,3 };
            try{
                System.out.println(arr[4]);
            }catch(ArrayIndexOutOfBoundsException e){
                System.out.println("捕获ArrayIndexOutOfBoundsException异常");
                e.printStackTrace();
            }
            System.out.println("666");
        }
        //try catch
        public static void main3(String[] args) {
            int[] arr = {1, 2, 3 };
            try{
                System.out.println(arr[4]);
                System.out.println("666");
            }catch(ArrayIndexOutOfBoundsException e){
                System.out.println("捕获ArrayIndexOutOfBoundsException异常");
            }
            System.out.println("666");
        }
        //thows声明错误信息
        public static void func()
            throws CloneNotSupportedException{
            Person person = new Person();
            person.clone();
        }
        public static void main2(String[] args)
            throws CloneNotSupportedException {
            func();
        }
        //throw扔出一个错误信息
        public static void testException(int x){
            if( x == 0){
                throw new ArithmeticException("x == 0");
                //throw new ArithmeticException();
            }
        }
        public static void main1(String[] args) {
            testException(0);
        }
    }
